#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_map>
using namespace std;

class Solution {
public:
    int maxNumOfMarkedIndices(vector<int>& nums) {
        sort(nums.begin(), nums.end());
        int ans = 0, n = nums.size();
        int m = n / 2;
        for (int left = 0, right = m; left < m && right < n; ++right)
        {
            if (2 * nums[left] <= nums[right])
            {
                ans += 2;
                ++left;
            }
        }
        return ans;
    }

    int subarraysDivByK(vector<int>& nums, int k) {
        unordered_map<int, int> hash;
        hash[0] = 1;
        int n = nums.size();
        int ans = 0, sum = 0;
        for (int num : nums)
        {
            sum += num;
            int r = (sum % k + k) % k;
            if (hash.count(r)) ans += hash[r];;
            ++hash[r];
        }
        return ans;
    }

    int minMoves(vector<int>& nums) {
        int minNum = *min_element(nums.begin(), nums.end());
        int res = 0;
        for (int num : nums)
            res += num - minNum;
        return res;
    }
};